<template>
  <div>
    <h1>员工列表</h1>
    <div>
      <input type="text" placeholder="请输入员工姓名" v-model="e.name">
      <input type="text" placeholder="请输入员工工资" v-model="e.salary">
      <input type="text" placeholder="请输入员工岗位" v-model="e.job">
      <button @click="add">添加</button>
    </div>
    <hr>
    <div >
      <table border="1px">
        <tr>
          <th>序号</th>
          <th>姓名</th>
          <th>薪水</th>
          <th>岗位</th>
        </tr>
        <tr v-for="(item,index) in list">
          <td>{{index+1}}</td>
          <td>{{item.name}}</td>
          <td>{{item.salary}}</td>
          <td>{{item.job}}</td>
        </tr>
      </table>
    </div>
  </div>
</template>
<script setup>
import {ref} from 'vue';
let e = ref({name: '', salary: '', job: ''});
let list = ref([]);
const add=()=> {
  if(e.value.name.trim()=='' || e.value.salary.trim()=='' || e.value.job.trim()==''){
    alert('请输入完整信息');
    return;
  }
  //向数组中放数据
  list.value.push(e.value);
  e.value = {name: '', salary: '', job: ''};
}
</script>
<style scoped>
 table{
   margin: 10px auto;width: 600px
 }
</style>